home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Tools / nsapexpand / nsapexpand.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  1.9 KB  |  107 lines

  1. /*  nsapexpand.c: expand macro forms of NSAP to full form */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Tools/nsapexpand/RCS/nsapexpand.c,v 6.0 1991/12/18 20:32:03 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Tools/nsapexpand/RCS/nsapexpand.c,v 6.0 1991/12/18 20:32:03 jpo Rel $
  9.  *
  10.  * $Log: nsapexpand.c,v $
  11.  * Revision 6.0  1991/12/18  20:32:03  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "util.h"
  19. #include <isode/isoaddrs.h>
  20.  
  21. static char    *myname;
  22. int    abortonerror = 0;
  23.  
  24. main (argc, argv)
  25. int    argc;
  26. char    **argv;
  27. {
  28.     extern char    *optarg;
  29.     extern int    optind;
  30.     int    opt;
  31.  
  32.     myname = argv[0];
  33.     sys_init (*argv);
  34.  
  35.     while((opt = getopt(argc, argv, "a")) != EOF)
  36.         switch (opt) {
  37.             case 'a':
  38.             abortonerror = TRUE;
  39.             break;
  40.  
  41.             default:
  42.             fprintf (stderr, "Usage: %s [-a] [files]\n", myname);
  43.             break;
  44.         }
  45.     argc -= optind;
  46.     argv += optind;
  47.  
  48.     if (argc <= 0)
  49.         process (stdin, "standard input");
  50.     else {
  51.         while (argc > 0) {
  52.             FILE    *fp = fopen (*argv, "r");
  53.             if (fp == NULL) {
  54.                 fprintf (stderr, "%s: Can't open file %s\n",
  55.                      myname, *argv);
  56.                 exit(1);
  57.             }
  58.             process (fp, *argv);
  59.             (void) fclose (fp);
  60.  
  61.             argv ++;
  62.             argc --;
  63.         }
  64.     }
  65.     exit (0);
  66. }
  67.  
  68. process (fp, name)
  69. FILE    *fp;
  70. char    *name;
  71. {
  72.     char    key[BUFSIZ], value[BUFSIZ];
  73.     struct PSAPaddr *pa;
  74.     char    *cp;
  75.  
  76.     while (tab_fetch (fp, key, value) == OK) {
  77.         if (lexequ (key, "default") == 0) {
  78.             printf ("%s:%s\n", key, value);
  79.             continue;
  80.         }
  81.         if ((pa = str2paddr (key)) == NULLPA) {
  82.             PP_OPER (NULLCP, ("Bad psap address <%s> in %s",
  83.                       key, name));
  84.             fprintf (stderr, "Bad psap address <%s> in %s\n",
  85.                       key, name);
  86.             if (abortonerror)
  87.                 exit (1);
  88.             continue;
  89.         }
  90.         cp = _paddr2str (pa, NULLNA, -1);
  91.         if (cp == NULLCP) {
  92.             PP_OPER (NULLCP,
  93.                  ("Can't convert psap <%s> to full form",
  94.                   key));
  95.             fprintf (stderr,
  96.                  "Can't convert psap <%s> to full form\n",
  97.                  key);
  98.             if (abortonerror)
  99.                 exit (1);
  100.             continue;
  101.         }
  102.         printf ("%s:%s\n", cp, value);
  103.     }
  104. }
  105.  
  106.         
  107.